package com.yntx.usercenter.base.controller;

import com.yntx.usercenter.base.dto.SystemDTO;
import com.yntx.usercenter.base.dto.SystemDeleteDTO;
import com.yntx.usercenter.base.dto.SystemUpdateDTO;
import com.yntx.usercenter.base.po.System;
import com.yntx.usercenter.base.service.impl.SystemServiceImpl;
import com.yntx.usercenter.common.web.ApiResult;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.security.NoSuchAlgorithmException;
import java.util.List;

@RestController
@RequestMapping("/system")
@AllArgsConstructor
public class SystemController {

    private SystemServiceImpl systemService;

    @GetMapping
    public ApiResult<System> getById(@RequestBody Long id) {
        System systemList = systemService.getById(id);
        return ApiResult.ofSuccess(systemList);
    }

    @PostMapping("/add")
    public ApiResult<Long> add(@RequestBody SystemDTO dto) throws NoSuchAlgorithmException {
        Long id = systemService.addSystem(dto);
        return ApiResult.ofSuccess(id);
    }

    @PostMapping("/delete")
    public ApiResult<?> delete(@RequestBody SystemDeleteDTO dto) {
        systemService.deleteSystem(dto);
        return ApiResult.ofSuccess();
    }

    @PostMapping("/update")
    public ApiResult<?> update(@RequestBody SystemUpdateDTO dto) {
        systemService.updateSystem(dto);
        return ApiResult.ofSuccess();
    }

    @PostMapping("/list")
    public ApiResult<List<System>> list(@RequestBody SystemDTO dto) {
        List<System> systemList = systemService.selectSystem(dto);
        return ApiResult.ofSuccess(systemList);
    }

}
